#!/usr/bin/python

import re, feedparser, twitter
import escapeHtml #Ad-hoc made module for escaping html strings.

# Zoho Creator db address
ZOHO_RSS_URL = 'http://yatuc.com/7dj'

# Get the feed
feed = feedparser.parse(ZOHO_RSS_URL)

# Parse the feed
for entry in feed.get('entries'):
	name = entry.get('zc_feed')
	srcpage = entry.get('zc_feed1')
	login = entry.get('zc_login')
	password = entry.get('zc_password')
	filter = entry.get('zc_filter_script')

	# Fetch the source
	page = urllib.urlopen(srcpage)
	string = page.read()

	# Parse the source
	for line in filter.splitlines():
		match = re.compile(unescape(line), re.DOTALL|re.MULTILINE).search(string)
		string = string[match.start():match.end()]
	
	# Send the string via twitter
	#twitbot = twitter.Api(username=login, password=password)
	#twitbot.PostUpdate(string)
	print string

